package com.XinYun.Library.modules.judge.controller;

import com.XinYun.Library.modules.display.response.ResponseWrapper;
import com.XinYun.Library.modules.judge.dao.sql;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

@WebServlet(name = "isbannedServlet", value = "/isbannedServlet")
public class isbannedServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求体数据
        BufferedReader reader = req.getReader();
        String readLine = reader.readLine();
        //将JSON字符转化为JAVA对象
        JSONObject jsonObject = JSON.parseObject(readLine);
        String sid = jsonObject.getString("sid");
        try {
                isbannedImpl.Judge(sid);
            if (isbannedImpl.Judge(sid)==1){
                ResponseWrapper responseWrapper=null;
                responseWrapper = ResponseWrapper.isban();
                String s=JSON.toJSONString(responseWrapper);
                PrintWriter writer = resp.getWriter();
                writer.println(s);
                System.out.println(s);
            }else{
                ResponseWrapper response=null;
                response = ResponseWrapper.notban();
                String s=JSON.toJSONString(response);
                PrintWriter writer = resp.getWriter();
                writer.println(s);
                System.out.println(s);
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
